package com.blog.aop;

import com.blog.common.CacheData;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author jiafujun
 * 2020-06-19 16:55:01
 **/
@Aspect
@Configuration
public class AspectHandle {
    private static Logger logger = LoggerFactory.getLogger(AspectHandle.class);

    @Pointcut(value = "execution(* com.blog.controller.*Controller.*(..))")
    public void excudeService() {

    }

    @After(value = "excudeService()")
    public void doBeforeMethod(JoinPoint joinPoint) {
        RequestAttributes ra = RequestContextHolder.getRequestAttributes();
        ServletRequestAttributes sra = (ServletRequestAttributes) ra;
        HttpServletRequest request = sra.getRequest();
        request.setAttribute("linkList", CacheData.getLinkData());
    }

}
